/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.ArrayList;
import model.Tinhtrangdaugia;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;

/**
 *
 * @author HoangLiem
 */
public class TinhTrangDauGiaDAO {

    public static ArrayList<Tinhtrangdaugia> getAllStatus() {
        ArrayList<Tinhtrangdaugia> list = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction trans = session.getTransaction();
            trans.begin();
            String hql = "from Tinhtrangdaugia";
            Query query = session.createQuery(hql);
            list = (ArrayList<Tinhtrangdaugia>) query.list();
            trans.commit();
        } catch (Exception ex) {
            list = null;
            ex.printStackTrace();
        }
        return list;
    }

    public static Tinhtrangdaugia getBidStatus(int maTinhTrang) {
        Tinhtrangdaugia tt = null;
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction trans = session.getTransaction();
            trans.begin();
            String hql = "from Tinhtrangdaugia ttdg where ttdg.maTinhTrang=:maTinhTrang";
            Query query = session.createQuery(hql);
            query.setInteger("maTinhTrang", maTinhTrang);
            tt = (Tinhtrangdaugia) query.uniqueResult();
            trans.commit();
        } catch (Exception ex) {
            tt = null;
            ex.printStackTrace();
        }
        return tt;
    }
}
